草庐IT

C++ 匿名变量

全部标签

javascript - 在匿名函数中声明函数

我正在查看的代码似乎声明了一个需要调用才能运行的函数。此函数是在匿名函数中声明的。这是否意味着这个block之外的任何东西都无法访问该函数?(function(){var_d=vjo.dsf.EventDispatcher;var_r=vjo.Registry;function$1(p0){returnfunction(event){returnthis.onSubmit(p0,event);};};})();为什么有人会这样做?我不确定这段代码中$的用途/相关性。 最佳答案 "Doesn'tthismeanthatthefunct

javascript - Javascript 变量作用域问题

我有一个变量mutedUser,我想将其保存到另一个函数。我在点击事件之外持续存在变量时遇到了一些麻烦。拥有它的最佳方式是什么,以便“returnmutedUser”会根据满足if语句的条件保留“muted”字符串添加?谢谢!*console.log是我检查持久性停止的地方this.isUserMuted=functionisUserMuted(payload){varmutedUser='';//Ifmutebuttonisclickedplacethemintomuteduserslist//checkforduplicatesinlist$("#messages-wrapper"

javascript - 引用模块中的全局变量

我在htmlheader中声明了一个全局变量,并想从模块内的类中引用它。如何防止编译器错误:错误TS2095:找不到符号“selfGlobal”。varselfGlobal=this;varglobalVariable=1;在测试中moduleTest{exportclassTestClass{private_privateVariable:any;constructor(){this._privateVariable=selfGlobal.globalVariable;//compileerrorthrowshere,butthecodecanrun}}}谢谢!火星

javascript - 如何确定变量是否未定义

这个问题在这里已经有了答案:HowcanIcheckfor"undefined"inJavaScript?[duplicate](16个答案)关闭8年前。在关于SO的另一个问题中,我正在确定如何关闭一个功能,工作解决方案是这样的:我将vardisabledFlag=true;放在我页面的头部,在调用shell.js之前,然后在shell.js中我有:/*******************************//*TOGGLEBUTTON/*******************************/vartoggleBlock=function(){console.log(di

JavaScript 模块模式——私有(private)变量与静态变量

所以这是著名的JavaScript模块模式的一个例子:varPerson=(function(){var_name;//socalled'privatevariable'functionPerson(name){_name=name;}Person.prototype.kill=function(){console.log(_name+'hasbeenshot');};returnPerson;})();varpaul=newPerson('Paul');paul.kill();到目前为止还不错吧?这会将'Paulhasbeenshot'记录到控制台,这正是我们想要的。但是。_name

javascript - 为什么函数名在分配给变量后不可用

这个问题在这里已经有了答案:Javascriptfunctionslike"varfoo=functionbar()..."?(9个回答)JavaScript-Whyisthisfunctiondeclarationcreatedinafunctionexpression"undefined"?(3个答案)关闭4年前。我刚刚在一次采访中遇到了这个问题。我没有得到任何答案,所以把它放在StackOverflow上JS中的一个简单问题,但我无法理解其背后的原因。下面是代码。varf=functionfoo(a,b){console.log(a+"-"+b);//f(1,2)willprin

javascript - 如何将元素附加到要在 react 中呈现的变量

给定如下所示的React组件(https://jsfiddle.net/69z2wepo/28684/):varHello=React.createClass({render:function(){let{cond,name}=this.props;letcontent,content2;if(cond){content=(Hello{name});content2=(content2);}return({content}{content2})}});ReactDOM.render(,document.getElementById('container'));我怎样才能实现这样的目标:

javascript - jQuery:是否可以将 DOM 元素分配给变量供以后使用?

我正在从事一个使用jQuery的项目,我对Mootools更加熟悉。我先从我的代码开始。varcustomNamespace={status:'closed',popup:$('#popup'),showPopup:function(){//...}}$(document).ready(function(){console.log($('#popup'));console.log(customNamespace.popup);console.log($(customNamespace.popup));$('#popup').fadeIn('slow');(customNamespace

javascript - 带有命名空间的 JavaScript 匿名函数的好处

编写这样的JavaScript类和命名空间有什么好处吗...if(typeofMyNamespace==='undefined'){varMyNamespace={};}(function(){MyNamespace.MyClass=function(){this.property='foo'returnthis;}}());与仅此相比...if(typeofMyNamespace==='undefined'){varMyNamespace={};}MyNamespace.MyClass=function(){this.property='foo'returnthis;}我已经在几个库

javascript传递eval变量

我有eval函数,需要从php执行javascript。但我需要传递元素,所以我可以将鼠标放在用户点击的链接上的提示上。varglobalEval=functionglobalEval(src,element){if(window.execScript){window.execScript(src);return;}varfn=function(element){window.eval.call(window,src);};fn(element);};我使用以下方式传递$(this)元素globalEval(js_code,$(this));//js_codeis=alert(elem